package com.example.demo.controller;


import com.example.demo.entity.User;
import com.example.demo.entity.USERO;
import com.example.demo.impl.UserServiceImpl;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.UserService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
import sun.rmi.runtime.Log;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zmh
 * @since 2021-06-30
 */
@RestController
@RequestMapping("/user")
@CrossOrigin(origins="http://localhost:8080")
public class UserController {
    @Autowired
    UserServiceImpl userService;

    @GetMapping("/getall")
    public List<User> getall(){
//        List<User> users = userMapper.findAll();
//        m.addAttribute("user",users);
        return userService.getList();
    }

    @GetMapping("/getalllist")
    public List<USERO> getalllist(){
        return userService.getALLList();
    }

    @GetMapping("/login")
    public Object login(String username,String password)
    {
        return  userService.login(username,password);
    }

    @GetMapping("/register")
    public  boolean register(String username,String password)
    {
        return  userService.register(username,password);
    }


    @GetMapping("/isvip")
    public boolean isvip(String username)
    {
        return userService.isvip(username);
    }

    @GetMapping("/findms")
    public List<User> findms(String name)
    {
        return  userService.findms(name);
    }

    @GetMapping("/insert")
     public boolean insert(String name,String username,String address,String phonenumber,String Email,String sex)
    {
        userService.insert(name,username,address,phonenumber,Email,sex);
        return true;

    }

    @GetMapping("/findby_oid")
    public String findby_oid(String openID)
    {
        if (userService.findby_oid(openID)==null)
        {
            return "false";
        }
        return "true";
    }
    @GetMapping("/huaweiuser")
    public Boolean addhuaweiuser(String username,String openID)
    {
        userService.addhuaweiuser(username, openID);
        return  true;
    }
    @GetMapping("/huaweiuserms")
    public boolean addhuaweiuserms(String name,String username,String phonenumber,String Email,String sex)
    {
        userService.addhuaweiuserms(name, username, phonenumber, Email, sex);
        return true;
    }

    @GetMapping("/updatevip")
    public boolean updatevip(String username)
    {
        userService.updatevip(username);
        return  true;
    }
}

